<template>
	<view class="content">
		<view class="mainpadding_top ffffff line_bottom" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="xiaohei main_size">{{item.paytype_name}}</view>
				<view class="xiaohuang main_size" v-if="item.status==1">審核中</view>
				<view class="xiaolv main_size" v-if="item.status==2">已完成</view>
				<view class="xiaohong main_size" v-if="item.status==3">審核失敗</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="xiaohuang bold main_size">{{item.price}}</view>
				<view class="color_jiu text_five">{{item.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="item.image">
				<view class="xiaohei main_size" >支付憑證</view>
				<image class="listleftimg1 radius" :src="item.image_text" mode=""></image>
			</view>
			<view class="xiaohei main_size margin_top" v-if="item.bz">備注：{{item.bz}}</view>
			<view class="flexright margin_top">
				<view class="listbtnhuang" @click.stop="currentid=item.id;show=true" v-if="item.status==1">上傳憑證</view>
			</view>
		</view>
		<u-modal :show="show" title="上傳憑證" confirmColor="#ffb800" confirmText="確認" @confirm="upconfirm" cancelText="取消"
			@cancel="show=false" showCancelButton>
			<view class="slot-content" style="width: 730rpx;">
				<view class="flexcenter">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in images_text" :key="index">
						<!-- 已上传 -->
						<view class="listleftimg1 radius">
							<image class="radius" :src="item" mode=""></image>
							<view class="deleteimg" @click="delindex(index,images,images_text)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(1,images,images_text)"
						v-if="images.length<1"><!-- 未上传 -->
						<image class="listleftimg1 radius" src="@/static/image/system/upimg.png" mode=""></image>
					</view>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				show: false,
				images_text: [],
				images: [],
				currentid:"",
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this
				let url = "/api/shop/rechargePirceIndex"
				let data = {
					page: page || 1,
					limit: _this.limit,
					shop_id: uni.getStorageSync("shop_id"),
				}
				httpRequest.request(url, 'GET', data).then(res => {
					if (res.code == 1) {
						let resList = res.data
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							// _this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相機', '相冊'],
					success: function(res) {
						// 選擇相機走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 選擇相簿走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				this.http.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
			upconfirm(){
				if(this.images.length==0){
					httpRequest.toast("請上傳圖片")
				}
				this.show = false
				httpRequest.request("/api/shop/uploadRechargeImage", 'GET', {
					id:this.currentid,
					image:this.images.join()
				}).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.images = []
						this.images_text = []
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.u-transition{
		z-index: 10 !important;
	}
	.price {
		font-size: 32rpx;
		font-family: DIN Next LT Pro-Bold;
		font-weight: Bold;
		color: rgba(255, 184, 0, 1);
	}

	.listleftimg1 {
		width: 120rpx;
		height: 120rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>